package com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.deepoove.poi.XWPFTemplate;
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ExceptionCast;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.util.ApiModelUtil;
import com.xyht.sca_s.student_manage_system.common.util.ParamCheckUtil;
import com.xyht.sca_s.student_manage_system.common.util.TimeUtil;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.entity.RxAdvanceRegistrationMiddleSchool;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.entity.RxAdvanceRegistrationOrg;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.mapper.RxAdvanceRegistrationMiddleSchoolMapper;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.mapper.RxAdvanceRegistrationOrgMapper;
import com.xyht.sca_s.student_manage_system.modules.common.constant.FileSavePathConstant;
import com.xyht.sca_s.student_manage_system.modules.common.entity.SmsImportTask;
import com.xyht.sca_s.student_manage_system.modules.common.entity.SmsImportTaskDetail;
import com.xyht.sca_s.student_manage_system.modules.common.mapper.SmsImportTaskDetailMapper;
import com.xyht.sca_s.student_manage_system.modules.common.mapper.SmsImportTaskMapper;
import com.xyht.sca_s.student_manage_system.modules.payment.wxpay.config.WxPayConfig;
import com.xyht.sca_s.student_manage_system.modules.payment.wxpay.entity.WxPayFunctions;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.entity.*;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.entity.req.RxRegistrationChargeCategoryRecordDetailReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.entity.req.RxRegistrationChargeCategoryRecordReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.entity.resp.RxRegistrationChargeCategoryDetailResp;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.entity.resp.RxRegistrationChargeCategoryRecordResp;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.mapper.*;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.service.RxRegistrationChargeCategoryRecordService;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.entity.RxRegistrationAdvanceStudentInfo;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.entity.req.RxOldRegistrationAdvanceStudentInfoReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.entity.req.RxRegistrationAdvanceCustomColumnValueReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.entity.req.RxRegistrationAdvanceStudentInfoAddReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.entity.req.RxRegistrationAdvanceStudentInfoBatchReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.entity.resp.*;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.mapper.RxRegistrationAdvanceStudentInfoMapper;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.service.RxRegistrationAdvanceStudentInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.util.PlanUtil;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationChargePayment.entity.RxRegistrationChargePaymentCategoryDivide;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationChargePayment.entity.RxRegistrationChargePaymentRecord;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationChargePayment.entity.req.RxRegistrationChargePaymentCategoryDivideReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationChargePayment.entity.req.RxRegistrationChargePaymentRecordReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationChargePayment.entity.resp.RxRegistrationPrepayPaymentResp;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationChargePayment.mapper.RxRegistrationChargePaymentCategoryDivideMapper;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationChargePayment.mapper.RxRegistrationChargePaymentRecordMapper;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationChargePayment.util.PaymentUtil;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationExamine.entity.RxRegistrationExamineBlackList;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationExamine.mapper.RxRegistrationExamineBlackListMapper;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationWelcome.entity.resp.RxRegistrationPlanChargeCategoryResp;
import lombok.extern.slf4j.Slf4j;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.springframework.beans.BeanUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

import static com.xyht.sca_s.student_manage_system.common.util.ParamCheckUtil.isNullOrEmpty;
import static com.xyht.sca_s.student_manage_system.modules.common.constant.TaskDetailReason.*;
import static com.xyht.sca_s.student_manage_system.modules.common.constant.TaskNameExample.TASK_NAME_OLD_REGISTRATION__STUDENT_IMPORT;
import static com.xyht.sca_s.student_manage_system.modules.common.constant.TaskStatus.TASK_STATUS_DONE;
import static com.xyht.sca_s.student_manage_system.modules.common.constant.TaskStatus.TASK_STATUS_ERR;
import static com.xyht.sca_s.student_manage_system.modules.common.constant.TaskTypeConstant.TASK_TYPE_OLD_REGISTRATION_STUDENT_IMPORT;
import static com.xyht.sca_s.student_manage_system.modules.common.constant.TaskTypeConstant.TASK_TYPE_TWO_OLD_REGISTRATION_STUDENT_IMPORT;
import static com.xyht.sca_s.student_manage_system.modules.rxRegistration.constant.AppTypeConstant.APP_TYPE_ADVANCE;
import static com.xyht.sca_s.student_manage_system.modules.rxRegistration.constant.ChargeCategoryTypeConstant.*;
import static com.xyht.sca_s.student_manage_system.modules.rxRegistration.constant.PlanStatusConstant.PLAN_STATUS_ENABLE;
import static com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.constant.RegistrationStatusConstant.REGISTRATION_STATUS_FINISH;
import static com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.constant.RegistrationStatusConstant.REGISTRATION_STATUS_GOING_ON;
import static com.xyht.sca_s.student_manage_system.modules.rxRegistrationChargePayment.constant.PaymentTypeConstant.RX_REGISTRATION_CHARGE_PAYMENT_RECORD_MODE_ONLINE;
import static com.xyht.sca_s.student_manage_system.modules.rxRegistrationChargePayment.constant.PaymentTypeConstant.RX_REGISTRATION_CHARGE_PAYMENT_RECORD_TYPE_ADVANCE;
import static com.xyht.sca_s.student_manage_system.modules.rxRegistrationWelcome.constant.IsStayConstant.IS_STAY;
import static com.xyht.sca_s.student_manage_system.modules.signUp.constant.SmsSignUpCommonConstant.PER_SHEET_NUM;

/**
 * <p>
 * 招生预报名学生信息 服务实现类
 * </p>
 *
 * @author XYHT
 * @since 2024-05-12
 */
@Service
@Slf4j
public class RxRegistrationAdvanceStudentInfoServiceImpl extends ServiceImpl<RxRegistrationAdvanceStudentInfoMapper, RxRegistrationAdvanceStudentInfo> implements RxRegistrationAdvanceStudentInfoService {

    @Resource
    private RxRegistrationAdvanceStudentInfoMapper rxRegistrationAdvanceStudentInfoMapper;
    @Resource
    private RxRegistrationPlanAppSettingMapper rxRegistrationPlanAppSettingMapper;
    @Resource
    private RxRegistrationPlanChargeCategorySettingMapper rxRegistrationPlanChargeCategorySettingMapper;
    @Resource
    private RxRegistrationPlanSettingMapper rxRegistrationPlanSettingMapper;
    @Resource
    private RxRegistrationChargeCategoryDetailMapper rxRegistrationChargeCategoryDetailMapper;
    @Resource
    private RxRegistrationChargeCategoryMapper rxRegistrationChargeCategoryMapper;
    @Resource
    private RxRegistrationCustomColumnMapper rxRegistrationCustomColumnMapper;
    @Resource
    private RxRegistrationCustomColumnValueMapper rxRegistrationCustomColumnValueMapper;
    @Resource
    private PlanUtil planUtil;
    @Resource
    private RxAdvanceRegistrationOrgMapper rxAdvanceRegistrationOrgMapper;
    @Resource
    private PaymentUtil paymentUtil;
    @Resource
    private RxRegistrationExamineBlackListMapper rxRegistrationExamineBlackListMapper;
    @Resource
    private RxRegistrationChargeCategoryRecordMapper rxRegistrationChargeCategoryRecordMapper;
    @Resource
    private RxRegistrationChargeCategoryRecordService rxRegistrationChargeCategoryRecordService;
    @Resource
    private ApiModelUtil apiModelUtil;
    @Resource
    private RxAdvanceRegistrationMiddleSchoolMapper rxAdvanceRegistrationMiddleSchoolMapper;
    @Resource
    private SmsImportTaskMapper smsImportTaskMapper;
    @Resource
    SmsImportTaskDetailMapper smsImportTaskDetailMapper;
    @Resource
    PlatformTransactionManager transactionManager;
    @Resource
    private RxRegistrationChargePaymentCategoryDivideMapper rxRegistrationChargePaymentCategoryDivideMapper;


    @Override
    public ResponseResult getAdvanceData() {
        RxRegistrationAdvanceDataResp rxRegistrationAdvanceDataResp = new RxRegistrationAdvanceDataResp();
        //获取自定义字段
        List<RxRegistrationAdvanceCustomColumnResp> customColumnRespList = new ArrayList<>();
        //获取收费项
        List<RxRegistrationAdvanceChargeCategoryResp> chargeCategoryRespList = new ArrayList<>();
        RxRegistrationPlanSetting planSetting = planUtil.getEnablePlanInfo();
        if (planSetting == null) {
            return CommonResult.success(customColumnRespList);
        }
        String planId = planSetting.getId();
        List<RxRegistrationCustomColumn> customColumnList = rxRegistrationCustomColumnMapper.selectList(new LambdaQueryWrapper<RxRegistrationCustomColumn>()
                .eq(RxRegistrationCustomColumn::getAppType, APP_TYPE_ADVANCE)
                .eq(RxRegistrationCustomColumn::getPlanId, planId)
                .orderByAsc(RxRegistrationCustomColumn::getColumnSort));
        if (customColumnList == null || customColumnList.size() == 0) {
            return CommonResult.success(customColumnRespList);
        }
        //获取自定义字段
        customColumnRespList = customColumnList.stream()
                .map(rxRegistrationCustomColumn -> {
                    RxRegistrationAdvanceCustomColumnResp customColumnResp = new RxRegistrationAdvanceCustomColumnResp();
                    BeanUtils.copyProperties(rxRegistrationCustomColumn, customColumnResp);
                    customColumnResp.setColumnId(rxRegistrationCustomColumn.getId());
                    return customColumnResp;
                })
                .collect(Collectors.toList());

        //获取收费项
        chargeCategoryRespList = rxRegistrationPlanChargeCategorySettingMapper.selectList(new LambdaQueryWrapper<RxRegistrationPlanChargeCategorySetting>()
                .eq(RxRegistrationPlanChargeCategorySetting::getPlanId, planId)
                .eq(RxRegistrationPlanChargeCategorySetting::getAppType, APP_TYPE_ADVANCE))
                .stream()
                .map(rxRegistrationPlanChargeCategorySetting -> {
                    RxRegistrationAdvanceChargeCategoryResp resp = new RxRegistrationAdvanceChargeCategoryResp();
                    RxRegistrationChargeCategory rxRegistrationChargeCategory = rxRegistrationChargeCategoryMapper.selectById(rxRegistrationPlanChargeCategorySetting.getChargeCategoryId());
                    if (isNullOrEmpty(rxRegistrationChargeCategory)) {
                        BeanUtils.copyProperties(rxRegistrationPlanChargeCategorySetting, resp);
                        resp.setChargeCategoryId(rxRegistrationPlanChargeCategorySetting.getId());
                    }
                    return resp;
                })
                .collect(Collectors.toList());
        rxRegistrationAdvanceDataResp.setChargeCategoryRespList(chargeCategoryRespList);
        rxRegistrationAdvanceDataResp.setCustomColumnRespList(customColumnRespList);
        return CommonResult.success(rxRegistrationAdvanceDataResp);
    }


    @Override
    public ResponseResult getAdvanceStuInfo(String idCard) {
        RxRegistrationAdvanceStudentInfoResp rxRegistrationAdvanceStudentInfoResp = new RxRegistrationAdvanceStudentInfoResp();
        //获取自定义字段
        List<RxRegistrationAdvanceCustomColumnValueResp> customColumnRespList = new ArrayList<>();
        //获取收费项
        List<RxRegistrationPlanChargeCategoryResp> chargeCategoryRespList = new ArrayList<>();
        if (isNullOrEmpty(idCard)) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }
        //身份证
        boolean validIDCard = ParamCheckUtil.isValidIDCard(idCard);
        if (!validIDCard) {
            return CommonResult.failed(CommonCodeEnum.ENROLLMENT_MANAGEMENT_STUDENT_ID_CARD_ERR);
        }
        //计划
        RxRegistrationPlanSetting planSetting = planUtil.getEnablePlanInfo();
        if (planSetting == null) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_PLAN_NOT_EXIST);
        }
        String planId = planSetting.getId();
        rxRegistrationAdvanceStudentInfoResp.setPlanId(planId);

        // 判断是否在黑名单中
        List<RxRegistrationExamineBlackList> blackList = rxRegistrationExamineBlackListMapper.selectList(new LambdaQueryWrapper<RxRegistrationExamineBlackList>()
                .eq(RxRegistrationExamineBlackList::getStuIdCard, idCard));
        if (blackList != null && blackList.size() > 0) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_BLACK_LIST_STUDENT_EXIST);
        }

        //获取招生计划下阶段招生开放时间
        Date nowDate = new Date();
        List<RxRegistrationPlanAppSetting> planAppSettingList = rxRegistrationPlanAppSettingMapper.selectList(new LambdaQueryWrapper<RxRegistrationPlanAppSetting>()
                .eq(RxRegistrationPlanAppSetting::getPlanId, planSetting.getId())
                .lt(RxRegistrationPlanAppSetting::getBgTime, nowDate) //开始时间小于当前时间
                .gt(RxRegistrationPlanAppSetting::getEndTime, nowDate)  //结束时间大于当前时间
                .orderByDesc(RxRegistrationPlanAppSetting::getAppType));
        if (planAppSettingList == null || planAppSettingList.size() == 0) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_NOT_SUBMIT);
        }

        //学生信息
        RxRegistrationAdvanceStudentInfo studentInfo = null;
        List<RxRegistrationAdvanceStudentInfo> advanceStudentInfoList = rxRegistrationAdvanceStudentInfoMapper.selectList(new LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo>()
                .eq(RxRegistrationAdvanceStudentInfo::getPlanId, planId)
                .eq(RxRegistrationAdvanceStudentInfo::getIdCard, idCard));
        //自定义字段
        List<RxRegistrationCustomColumn> customColumnList = rxRegistrationCustomColumnMapper.selectList(new LambdaQueryWrapper<RxRegistrationCustomColumn>()
                .eq(RxRegistrationCustomColumn::getAppType, APP_TYPE_ADVANCE)
                .eq(RxRegistrationCustomColumn::getPlanId, planId)
                .orderByAsc(RxRegistrationCustomColumn::getAppType)
                .orderByAsc(RxRegistrationCustomColumn::getColumnSort));
        //有学生信息
        if (advanceStudentInfoList != null && advanceStudentInfoList.size() > 0) {
            studentInfo = advanceStudentInfoList.get(0);
            BeanUtils.copyProperties(studentInfo, rxRegistrationAdvanceStudentInfoResp);
            rxRegistrationAdvanceStudentInfoResp.setStuId(studentInfo.getId());
            String studentId = studentInfo.getId();
            if (customColumnList != null && customColumnList.size() > 0) {
                for (RxRegistrationCustomColumn rxRegistrationCustomColumn : customColumnList) {
                    //设置的自定义字段和添加的数据对比
                    RxRegistrationAdvanceCustomColumnValueResp customColumnValueResp = new RxRegistrationAdvanceCustomColumnValueResp();
                    List<RxRegistrationCustomColumnValue> columnValueList = rxRegistrationCustomColumnValueMapper.selectList(
                            new LambdaQueryWrapper<RxRegistrationCustomColumnValue>()
                                    .eq(RxRegistrationCustomColumnValue::getColumnId, rxRegistrationCustomColumn.getId())
                                    .eq(RxRegistrationCustomColumnValue::getPlanId, planId)
                                    .eq(RxRegistrationCustomColumnValue::getStudentId, studentId)
                                    .orderByAsc(RxRegistrationCustomColumnValue::getColumnSort));
                    //有数据 则返回数据和字段名
                    if (columnValueList != null && columnValueList.size() > 0) {
                        BeanUtils.copyProperties(columnValueList.get(0), customColumnValueResp);
                        customColumnValueResp.setColumnId(columnValueList.get(0).getId());
                    } else { //没有数据 则返回字段名
                        BeanUtils.copyProperties(rxRegistrationCustomColumn, customColumnValueResp);
                        customColumnValueResp.setColumnId(rxRegistrationCustomColumn.getId());
                    }
                    customColumnRespList.add(customColumnValueResp);
                }
            }

        } else {//没有学生信息

            //获取自定义字段
            customColumnRespList = customColumnList.stream()
                    .map(rxRegistrationCustomColumn -> {
                        RxRegistrationAdvanceCustomColumnValueResp customColumnResp = new RxRegistrationAdvanceCustomColumnValueResp();
                        BeanUtils.copyProperties(rxRegistrationCustomColumn, customColumnResp,"id");
                        customColumnResp.setColumnId(rxRegistrationCustomColumn.getId());
                        return customColumnResp;
                    })
                    .collect(Collectors.toList());

        }


        if (studentInfo == null || studentInfo.getAdvanceStatus() != REGISTRATION_STATUS_FINISH) {
            chargeCategoryRespList = rxRegistrationPlanChargeCategorySettingMapper.selectList(new LambdaQueryWrapper<RxRegistrationPlanChargeCategorySetting>()
                    .eq(RxRegistrationPlanChargeCategorySetting::getPlanId, planId)
                    .eq(RxRegistrationPlanChargeCategorySetting::getAppType, APP_TYPE_ADVANCE))
                    .stream()
                    .map(rxRegistrationPlanChargeCategorySetting -> {
                        RxRegistrationPlanChargeCategoryResp resp = new RxRegistrationPlanChargeCategoryResp();
                        RxRegistrationChargeCategory rxRegistrationChargeCategory = rxRegistrationChargeCategoryMapper.selectById(rxRegistrationPlanChargeCategorySetting.getChargeCategoryId());
                        if (!isNullOrEmpty(rxRegistrationChargeCategory)) {
                            BeanUtils.copyProperties(rxRegistrationPlanChargeCategorySetting, resp);
                        }
                        if (rxRegistrationPlanChargeCategorySetting.getChargeCategoryType() != CHARGE_CATEGORY_TYPE_NORMAL) {
                            List<RxRegistrationChargeCategoryDetailResp> childList = JSONObject.parseArray(rxRegistrationPlanChargeCategorySetting.getChargeCategoryChildren(), RxRegistrationChargeCategoryDetailResp.class);
                            resp.setChildList(childList);
                        }
                        return resp;
                    })
                    .collect(Collectors.toList());

        }
        //封装自定义字段
        rxRegistrationAdvanceStudentInfoResp.setCustomColumnValueList(customColumnRespList);
        //封装缴费项记录信息
        rxRegistrationAdvanceStudentInfoResp.setChargeCategoryRecordRespList(getChargeCategoryRecordList(studentInfo));
        //获取要缴费的收费项
        rxRegistrationAdvanceStudentInfoResp.setChargeCategoryRespList(chargeCategoryRespList);
        return CommonResult.success(rxRegistrationAdvanceStudentInfoResp);
    }


    @Transactional
    @Override
    public ResponseResult advancePayment(RxRegistrationAdvanceStudentInfoAddReq req) {

        //参数校验
        if (isNullOrEmpty(req.getPlanId(),req.getName(),req.getMiddleSchool(),req.getMiddleSchoolId(),req.getParentTel(),
                req.getIdCard(),req.getTel(),req.getOpenId())) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        //校验计划
        String planId = req.getPlanId();
        //查询计划是否存在并启用
        List<RxRegistrationPlanSetting> planSettingList = rxRegistrationPlanSettingMapper.selectList(new LambdaQueryWrapper<RxRegistrationPlanSetting>()
                .eq(RxRegistrationPlanSetting::getId, planId)
                .eq(RxRegistrationPlanSetting::getPlanStatus, PLAN_STATUS_ENABLE));
        if (planSettingList.isEmpty()) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_PLAN_NOT_EXIST);
        }
        String planName = planSettingList.get(0).getPlanName();
        //校验提交预报名是否在计划有效期内
        List<RxRegistrationPlanAppSetting> appSettingList = rxRegistrationPlanAppSettingMapper.selectList(new LambdaQueryWrapper<RxRegistrationPlanAppSetting>()
                .eq(RxRegistrationPlanAppSetting::getPlanId, planId)
                .eq(RxRegistrationPlanAppSetting::getAppType, APP_TYPE_ADVANCE));
        if (appSettingList.isEmpty()) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_PLAN_NOT_EXIST);
        }
        //获取招生计划下阶段招生开放时间
        Date nowDate = new Date();
        List<RxRegistrationPlanAppSetting> planAppSettingList = rxRegistrationPlanAppSettingMapper.selectList(new LambdaQueryWrapper<RxRegistrationPlanAppSetting>()
                .eq(RxRegistrationPlanAppSetting::getPlanId, planId)
                .lt(RxRegistrationPlanAppSetting::getBgTime, nowDate) //开始时间小于当前时间
                .gt(RxRegistrationPlanAppSetting::getEndTime, nowDate)  //结束时间大于当前时间
                .orderByDesc(RxRegistrationPlanAppSetting::getAppType));
        if (planAppSettingList == null || planAppSettingList.size() == 0) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_NOT_SUBMIT);
        }


        //校验自定义必填字段
        List<RxRegistrationAdvanceCustomColumnValueReq> customColumnValueList = req.getCustomColumnValueList();//传入的自定义字段
        List<RxRegistrationCustomColumn> customColumnList = rxRegistrationCustomColumnMapper.selectList(new LambdaQueryWrapper<RxRegistrationCustomColumn>()
                .eq(RxRegistrationCustomColumn::getAppType, APP_TYPE_ADVANCE)
                .eq(RxRegistrationCustomColumn::getPlanId, planId));//设置的自定义字段
        //设置了自定义字段
        if (customColumnList != null && customColumnList.size() > 0) {
            if (customColumnList.size() != customColumnValueList.size()) {
                return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
            }


            for (RxRegistrationAdvanceCustomColumnValueReq rxRegistrationAdvanceCustomColumnValueReq : customColumnValueList) {
                if (rxRegistrationAdvanceCustomColumnValueReq.getIsRequired()) {
                    //自定义字段为空
                    if (isNullOrEmpty(rxRegistrationAdvanceCustomColumnValueReq.getColumnValue(),rxRegistrationAdvanceCustomColumnValueReq.getColumnId())) {
                        ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.ADVANCE_REGISTRATION_CUSTOM_COLUMN_NOT_SET));
                    }
                }

            }
        }


        //校验身份证和电话
        boolean validIDCard = ParamCheckUtil.isValidIDCard(req.getIdCard());
        if (!validIDCard) {
            return CommonResult.failed(CommonCodeEnum.ENROLLMENT_MANAGEMENT_STUDENT_ID_CARD_ERR);
        }
        boolean validPhone = ParamCheckUtil.isValidPhone(req.getTel());
        if (!validPhone) {
            return CommonResult.failed(CommonCodeEnum.ADVANCE_REGISTRATION_TEL_ERR);
        }
        //校验组织
        String orgName = null;
        if (!isNullOrEmpty(req.getOrgId())) {
            RxAdvanceRegistrationOrg advanceRegistrationOrg = rxAdvanceRegistrationOrgMapper.selectById(req.getOrgId());
            if (isNullOrEmpty(advanceRegistrationOrg)) {
                return CommonResult.failed(CommonCodeEnum.ADVANCE_REGISTRATION_ORG_NOT_EXIST);
            }
            orgName = advanceRegistrationOrg.getMajorName();
        }


        //构造支付参数
        RxRegistrationChargePaymentRecordReq recordReq = new RxRegistrationChargePaymentRecordReq();
        List<RxRegistrationChargePaymentCategoryDivideReq> divideReqList ;

        // 获取商户集合
        List<WxPayFunctions> wxPayFunctionsList = WxPayConfig.wxPayFunctionsList;
        if (wxPayFunctionsList.isEmpty()) {
            ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.FAIL));
        }
        // 校验前端传入的商户Type
        RxRegistrationPlanSetting enablePlanInfo = planUtil.getEnablePlanInfo();
        if (enablePlanInfo == null) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_PLAN_NOT_EXIST);
        }
        Integer wxPayFunctionSort = enablePlanInfo.getPlanChargeShopSort();
        if (wxPayFunctionSort == null || wxPayFunctionSort <= 0
                || wxPayFunctionSort > wxPayFunctionsList.size() + 1) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }
        // 获取用户选择的商户
        WxPayFunctions wxPayFunction = wxPayFunctionsList.get(wxPayFunctionSort - 1);

        //学生id
        String stuId = null;
        List<RxRegistrationAdvanceStudentInfo> studentInfoList = rxRegistrationAdvanceStudentInfoMapper.selectList(new LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo>()
                .eq(RxRegistrationAdvanceStudentInfo::getPlanId, planId)
                .eq(RxRegistrationAdvanceStudentInfo::getIdCard, req.getIdCard()));
        if (!studentInfoList.isEmpty()) {
            stuId = studentInfoList.get(0).getId();
        }
        if (isNullOrEmpty(stuId)) {
            //创建学生信息
            RxRegistrationAdvanceStudentInfo rxRegistrationAdvanceStudentInfo = new RxRegistrationAdvanceStudentInfo();
            BeanUtils.copyProperties(req, rxRegistrationAdvanceStudentInfo);
            rxRegistrationAdvanceStudentInfo.setPlanName(planName);
            rxRegistrationAdvanceStudentInfo.setOrgName(orgName);
            rxRegistrationAdvanceStudentInfo.setAdvanceStatus(REGISTRATION_STATUS_GOING_ON);
            rxRegistrationAdvanceStudentInfoMapper.insert(rxRegistrationAdvanceStudentInfo);

            stuId = rxRegistrationAdvanceStudentInfo.getId();
            if (isNullOrEmpty(stuId)) {
                return CommonResult.failed(CommonCodeEnum.FAIL);
            }
            //创建该学生自定义信息
            if (customColumnValueList != null && customColumnValueList.size() > 0) {
                for (RxRegistrationAdvanceCustomColumnValueReq rxRegistrationAdvanceCustomColumnValueReq : customColumnValueList) {
                    RxRegistrationCustomColumnValue rxRegistrationAdvanceCustomColumnValue = new RxRegistrationCustomColumnValue();
                    BeanUtils.copyProperties(rxRegistrationAdvanceCustomColumnValueReq, rxRegistrationAdvanceCustomColumnValue,"id");
                    rxRegistrationAdvanceCustomColumnValue.setStudentId(stuId);
                    rxRegistrationAdvanceCustomColumnValue.setPlanId(planId);
                    rxRegistrationCustomColumnValueMapper.insert(rxRegistrationAdvanceCustomColumnValue);
                }
            }

        } else {
            //修改学生信息
            RxRegistrationAdvanceStudentInfo rxRegistrationAdvanceStudentInfo = studentInfoList.get(0);
            if (isNullOrEmpty(rxRegistrationAdvanceStudentInfo)) {
                return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
            }
            if (rxRegistrationAdvanceStudentInfo.getAdvanceStatus() == REGISTRATION_STATUS_FINISH) {
                return CommonResult.failed(CommonCodeEnum.ADVANCE_REGISTRATION_HAS_PAYED);
            }
            BeanUtils.copyProperties(req, rxRegistrationAdvanceStudentInfo);
            rxRegistrationAdvanceStudentInfo.setPlanName(planName);
            rxRegistrationAdvanceStudentInfo.setOrgName(orgName);
            rxRegistrationAdvanceStudentInfoMapper.updateById(rxRegistrationAdvanceStudentInfo);

            //修改该学生自定义信息
            if (customColumnValueList != null && customColumnValueList.size() > 0) {
                for (RxRegistrationAdvanceCustomColumnValueReq rxRegistrationAdvanceCustomColumnValueReq : customColumnValueList) {
                    RxRegistrationCustomColumnValue rxRegistrationCustomColumnValue = new RxRegistrationCustomColumnValue();
                    BeanUtils.copyProperties(rxRegistrationAdvanceCustomColumnValueReq, rxRegistrationCustomColumnValue);
                    rxRegistrationCustomColumnValueMapper.update(rxRegistrationCustomColumnValue,new LambdaQueryWrapper<RxRegistrationCustomColumnValue>()
                            .eq(RxRegistrationCustomColumnValue::getPlanId, planId)
                            .eq(RxRegistrationCustomColumnValue::getStudentId, stuId)
                            .eq(RxRegistrationCustomColumnValue::getColumnId, rxRegistrationAdvanceCustomColumnValueReq.getColumnId()));
                }
            }

        }

        //获取收费项
        divideReqList = chargeCategoryOperation(stuId,req.getChargeCategoryRecordList());


        //支付所需的信息
        recordReq.setStuId(stuId);
        recordReq.setPlanId(planId);
        recordReq.setType(RX_REGISTRATION_CHARGE_PAYMENT_RECORD_TYPE_ADVANCE);
        recordReq.setOpenId(req.getOpenId());
        recordReq.setWxPayFunction(wxPayFunction);
        recordReq.setMode(RX_REGISTRATION_CHARGE_PAYMENT_RECORD_MODE_ONLINE);
        recordReq.setDivideReqList(divideReqList);
        RxRegistrationPrepayPaymentResp prepayPaymentResp = paymentUtil.payment(recordReq);
        if (prepayPaymentResp == null) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_PAYMENT_FAIL);
        }

        return CommonResult.success(prepayPaymentResp);
    }


    /**
     * @description 收费项处理  校验并输出收费项集合
     * @create 2024/5/21
     * @author dxn
     */
    private List<RxRegistrationChargePaymentCategoryDivideReq> chargeCategoryOperation(String stu_id,
                                                                                       List<RxRegistrationChargeCategoryRecordReq> chargeCategoryRecordList) {
        List<RxRegistrationChargePaymentCategoryDivideReq> divideList = new ArrayList<>();

        RxRegistrationAdvanceStudentInfo studentInfo = rxRegistrationAdvanceStudentInfoMapper.selectById(stu_id);

        //获取收费项设置列表
        List<RxRegistrationPlanChargeCategoryResp> pendingChargeCategoryList = getChargeCategoryRespList(studentInfo.getPlanId(), studentInfo);

        for (RxRegistrationPlanChargeCategoryResp pendingChargeCategory : pendingChargeCategoryList) {
            //匹配与系统收费项集合进行匹配
            List<RxRegistrationChargeCategoryRecordReq> filterList = chargeCategoryRecordList
                    .stream()
                    .filter(record -> record.getMainId().equals(pendingChargeCategory.getChargeCategoryId()))
                    .collect(Collectors.toList());
            //判断是否必填
            if (pendingChargeCategory.getIsRequired()) {
                //必填 且未填写 报错
                if (filterList.size() < 1) {
                    ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_CONFIRM_CHARGE_CATEGORY_REQUIRED_NOT_FILL));
                }
            }

            //不必填 且未填写 跳过
            if (filterList.size() < 1) {
                continue;
            }

            //校验已填写单选 多选
            RxRegistrationChargeCategoryRecordReq filterRecord = filterList.get(0);
            if (pendingChargeCategory.getChargeCategoryType() == CHARGE_CATEGORY_TYPE_SIGNAL) {
                if (filterRecord.getChildList().size() != 1) {
                    ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_CONFIRM_CHARGE_CATEGORY_REQUIRED_FILL_ERROR));
                }

                String childId = filterRecord.getChildList().get(0).getChildId();
                addChargeCategoryToList(divideList, pendingChargeCategory, childId);
            } else if (pendingChargeCategory.getChargeCategoryType() == CHARGE_CATEGORY_TYPE_MULTIPLE) {
                if (filterRecord.getChildList().size() > pendingChargeCategory.getChildList().size()
                        || filterRecord.getChildList().size() < 1) {
                    ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_CONFIRM_CHARGE_CATEGORY_REQUIRED_FILL_ERROR));
                }

                for (RxRegistrationChargeCategoryRecordDetailReq childRecord : filterRecord.getChildList()) {
                    String childId = childRecord.getChildId();
                    addChargeCategoryToList(divideList, pendingChargeCategory, childId);
                }
            } else {
                addChargeCategoryToList(divideList, pendingChargeCategory, null);
            }
        }

        //删除缴费项记录
        if (studentInfo.getAdvanceStatus() != REGISTRATION_STATUS_FINISH) {
            LambdaQueryWrapper<RxRegistrationChargeCategoryRecord> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(RxRegistrationChargeCategoryRecord::getStuId, stu_id)
                    .and(wrapper -> {
                        if (studentInfo.getAdvanceStatus() != REGISTRATION_STATUS_FINISH) {
                            wrapper.eq(RxRegistrationChargeCategoryRecord::getAppType, APP_TYPE_ADVANCE);
                        }
                    });
            rxRegistrationChargeCategoryRecordMapper.delete(queryWrapper);
        }
        //保存记录
        List<RxRegistrationChargeCategoryRecord> recordList = divideList.stream()
                .map(divide -> {
                    RxRegistrationChargeCategoryRecord record = new RxRegistrationChargeCategoryRecord();
                    record.setStuId(stu_id);
                    record.setAppType(APP_TYPE_ADVANCE);
                    record.setMainId(divide.getCategoryId());
                    record.setMainName(divide.getCategoryName());
//                    record.setMainType(pendingChargeCategoryList.stream()
//                            .filter(pendingChargeCategory -> pendingChargeCategory.getChargeCategoryId().equals(divide.getCategoryId())));
                    record.setPrice(divide.getAmount());
                    record.setChildId(divide.getCategoryDetailId());
                    record.setChildName(divide.getCategoryDetailName());
                    return record;
                })
                .collect(Collectors.toList());
        rxRegistrationChargeCategoryRecordService.saveBatch(recordList);
        return divideList;
    }
    private List<RxRegistrationPlanChargeCategoryResp> getChargeCategoryRespList(String planId,
                                                                                 RxRegistrationAdvanceStudentInfo studentInfo) {
        List<RxRegistrationPlanChargeCategoryResp> chargeCategoryRespList = new ArrayList<>();
        if (studentInfo != null
                && studentInfo.getAdvanceStatus() == REGISTRATION_STATUS_FINISH) {
            return chargeCategoryRespList;
        }
        LambdaQueryWrapper<RxRegistrationPlanChargeCategorySetting> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RxRegistrationPlanChargeCategorySetting::getPlanId, planId)
                .and(wrapper -> {
                    if (studentInfo == null || studentInfo.getAdvanceStatus() != REGISTRATION_STATUS_FINISH) {
                        wrapper.eq(RxRegistrationPlanChargeCategorySetting::getAppType, APP_TYPE_ADVANCE);
                    }
                })
                .orderByAsc(RxRegistrationPlanChargeCategorySetting::getAppType);
        List<RxRegistrationPlanChargeCategorySetting> settingList = rxRegistrationPlanChargeCategorySettingMapper.selectList(queryWrapper);
        chargeCategoryRespList = settingList
                .stream()
                .map(setting -> {
                    RxRegistrationPlanChargeCategoryResp chargeCategoryResp = new RxRegistrationPlanChargeCategoryResp();
                    BeanUtils.copyProperties(setting, chargeCategoryResp);

                    if (setting.getChargeCategoryType() != CHARGE_CATEGORY_TYPE_NORMAL) {
                        List<RxRegistrationChargeCategoryDetailResp> childList = JSONObject.parseArray(setting.getChargeCategoryChildren(), RxRegistrationChargeCategoryDetailResp.class);
                        chargeCategoryResp.setChildList(childList);
                    }
                    return chargeCategoryResp;
                }).collect(Collectors.toList());
        return chargeCategoryRespList;
    }

    private List<RxRegistrationChargeCategoryRecordResp> getChargeCategoryRecordList(RxRegistrationAdvanceStudentInfo studentInfo) {
        List<RxRegistrationChargeCategoryRecordResp> chargeCategoryRecordRespList = new ArrayList<>();
        LambdaQueryWrapper<RxRegistrationChargeCategoryRecord> queryWrapper = new LambdaQueryWrapper<>();
        if (studentInfo == null) {
            return chargeCategoryRecordRespList;
        }
        queryWrapper.eq(RxRegistrationChargeCategoryRecord::getStuId, studentInfo.getId())
                .orderByAsc(RxRegistrationChargeCategoryRecord::getAppType);

        if (studentInfo.getAdvanceStatus() == REGISTRATION_STATUS_FINISH) {
            queryWrapper.and(wrapper -> {
                if (studentInfo.getAdvanceStatus() == REGISTRATION_STATUS_FINISH) {
                    wrapper.eq(RxRegistrationChargeCategoryRecord::getAppType, APP_TYPE_ADVANCE);
                }
            });

        } else {
            return chargeCategoryRecordRespList;
        }
        chargeCategoryRecordRespList = rxRegistrationChargeCategoryRecordMapper.selectList(queryWrapper)
                .stream()
                .map(record -> {
                    RxRegistrationChargeCategoryRecordResp chargeCategoryResp = new RxRegistrationChargeCategoryRecordResp();
                    BeanUtils.copyProperties(record, chargeCategoryResp);
                    return chargeCategoryResp;
                })
                .collect(Collectors.toList());
        return chargeCategoryRecordRespList;
    }

    private void addChargeCategoryToList(List<RxRegistrationChargePaymentCategoryDivideReq> divideList,
                                         RxRegistrationPlanChargeCategoryResp pendingChargeCategory,
                                         String childId) {
        RxRegistrationChargePaymentCategoryDivideReq divideReq = new RxRegistrationChargePaymentCategoryDivideReq();
        divideReq.setCategoryId(pendingChargeCategory.getChargeCategoryId());
        divideReq.setCategoryName(pendingChargeCategory.getChargeCategoryName());
        if (!isNullOrEmpty(childId)) {
            List<RxRegistrationChargeCategoryDetailResp> childFilterRecordList = pendingChargeCategory.getChildList()
                    .stream()
                    .filter(child -> child.getChargeCategoryId().equals(childId))
                    .collect(Collectors.toList());
            if (childFilterRecordList.size() < 1) {
                ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_CONFIRM_CHARGE_CATEGORY_CHILD_ERROR));
            }
            divideReq.setCategoryDetailId(childFilterRecordList.get(0).getChargeCategoryId());
            divideReq.setCategoryDetailName(childFilterRecordList.get(0).getChargeCategoryName());
            divideReq.setAmount(childFilterRecordList.get(0).getChargeCategoryPrice());
        } else {
            divideReq.setAmount(pendingChargeCategory.getChargeCategoryPrice());
        }
        divideList.add(divideReq);
    }

    @Override
    public ResponseResult updateStuInfo(RxRegistrationAdvanceStudentInfoAddReq addReq) {
        if (isNullOrEmpty(addReq.getStuId(),addReq.getIdCard(),addReq.getOrgId(),addReq.getTel())) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }
        //身份证
        String idCard = addReq.getIdCard();
        RxRegistrationAdvanceStudentInfo rxRegistrationAdvanceStudentInfo = rxRegistrationAdvanceStudentInfoMapper.selectById(addReq.getStuId());
        if (isNullOrEmpty(rxRegistrationAdvanceStudentInfo)) {
            return CommonResult.failed(CommonCodeEnum.ADVANCE_REGISTRATION_DATA_UPDATE);
        }
        List<RxRegistrationAdvanceStudentInfo> studentInfoList = rxRegistrationAdvanceStudentInfoMapper.selectList(new LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo>()
                .eq(RxRegistrationAdvanceStudentInfo::getIdCard, idCard)
                .eq(RxRegistrationAdvanceStudentInfo::getPlanId, rxRegistrationAdvanceStudentInfo.getPlanId())
                .ne(RxRegistrationAdvanceStudentInfo::getId, addReq.getStuId()));
        if (studentInfoList != null && studentInfoList.size() > 0) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_STUDENT_ID_CARD_EXIT);
        }
        //初中学校
        RxAdvanceRegistrationMiddleSchool middleSchool = rxAdvanceRegistrationMiddleSchoolMapper.selectById(addReq.getMiddleSchoolId());
        if (isNullOrEmpty(middleSchool)) {
            return CommonResult.failed(CommonCodeEnum.ADVANCE_REGISTRATION_MIDDLE_SCHOOL_NOT_EXIST);
        }
        BeanUtils.copyProperties(addReq,rxRegistrationAdvanceStudentInfo);
        rxRegistrationAdvanceStudentInfo.setMiddleSchoolId(addReq.getMiddleSchoolId());
        rxRegistrationAdvanceStudentInfo.setMiddleSchool(middleSchool.getMiddleSchoolName());
        rxRegistrationAdvanceStudentInfoMapper.updateById(rxRegistrationAdvanceStudentInfo);
        return CommonResult.success();
    }

    @Resource
    private FileSavePathConstant fileSavePathConstant;
    @Resource
    private RxRegistrationChargePaymentRecordMapper rxRegistrationChargePaymentRecordMapper;
    @Override
    @Async
    public Future<ResponseResult> admissionDownload(String stuId, HttpServletResponse response) {

        RxRegistrationAdvanceStudentInfo studentInfo = rxRegistrationAdvanceStudentInfoMapper.selectById(stuId);
        if (studentInfo == null || studentInfo.getId() == null) {
            return new AsyncResult<>(CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_STUDENT_NOT_EXIT));
        }
        //预报名阶段是否完成缴费
        if (studentInfo.getAdvanceStatus() != REGISTRATION_STATUS_FINISH) {
            return new AsyncResult<>(CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_NOT_FINISH));
        }
        //查询缴费记录表
        List<RxRegistrationChargePaymentRecord> paymentRecordList = rxRegistrationChargePaymentRecordMapper.selectList(new LambdaQueryWrapper<RxRegistrationChargePaymentRecord>()
                .eq(RxRegistrationChargePaymentRecord::getStuId, stuId)
                .eq(RxRegistrationChargePaymentRecord::getType, RX_REGISTRATION_CHARGE_PAYMENT_RECORD_TYPE_ADVANCE));
        if (paymentRecordList == null || paymentRecordList.size() < 1) {
            return new AsyncResult<>(CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_NOT_FINISH));
        }

        String OSName = System.getProperty("os.name");
        String filePath = OSName.toLowerCase().startsWith("win") ? fileSavePathConstant.getFILE_DOWNLOAD_PATH()
                : fileSavePathConstant.getFILE_DOWNLOAD_PATH_LINUX();

        String newFilePath = filePath  + System.currentTimeMillis() + ".docx";
        String pdfFilePath = filePath  + System.currentTimeMillis() + ".pdf";

        File pdfFile = new File(pdfFilePath);

        try {
            //支付时间
            Date paymentTime = paymentRecordList.get(0).getPaymentTime();
            String paymentTimeStr = TimeUtil.DateHanZiSimpleFormat(paymentTime);
            Map<String, Object> map = new HashMap<>();
            map.put("name", studentInfo.getName());
            map.put("number", "D" +  studentInfo.getAdmissionNumber());//D240001
            map.put("majorName", studentInfo.getOrgName());
            map.put("1", paymentTimeStr.substring(0, 4));//年 2024年12月31日
            map.put("2", paymentTimeStr.substring(5, 7));//月
            map.put("3", paymentTimeStr.substring(8, 10));//日

            InputStream is ;
            ClassPathResource resource = new ClassPathResource("applyTemplates/admission.docx");
            is = resource.getInputStream();
            FileOutputStream outputStream = new FileOutputStream(newFilePath);
            XWPFTemplate template = XWPFTemplate.compile(is);

            //配置图片标签
            template.render(map);
            template.write(outputStream);

            is.close();
            outputStream.close();
            template.close();

            //word转pdf
            File destOri = new File(newFilePath);
            FileInputStream fileInputStream = new FileInputStream(destOri);
            FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath);

            Document document = new Document();
            document.loadFromStream(fileInputStream, FileFormat.Docx);
            //保存为PDF
            document.saveToFile(pdfFilePath, FileFormat.PDF);
            fileInputStream.close();
            fileOutputStream.close();
            document.close();
            // 加载PDF文档
            PDDocument doc = PDDocument.load(pdfFile);
            doc.setAllSecurityToBeRemoved(true);
            response.setCharacterEncoding("utf-8");
            response.setContentType("application/vnd.pdf;charset=utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("录取通知书预览.pdf", "utf-8"));
            response.setHeader("file-name", URLEncoder.encode("录取通知书预览.pdf", "utf-8"));
            response.setHeader("file-type", "download");
            response.setHeader("Access-Control-Expose-Headers", "file-type,file-name");

            //刷新缓冲
            response.flushBuffer();
            // 保存PDF文档
            doc.save(response.getOutputStream());
            doc.close();
        } catch (Exception e) {
            e.printStackTrace();
            return new AsyncResult<>(CommonResult.failed(CommonCodeEnum.FAIL));
        }
        return null;
    }

    @Override
    public ResponseResult getStuInfoList(Integer pageNum, Integer pageSize, String stuName, String planId, Integer isStay, String tel, String middleSchoolId, String majorId, String idCard, Integer isFilingStu) {
        Page<RxRegistrationAdvanceStudentInfo> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo> studentInfoLambdaQueryWrapper = new LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo>()
                .orderByDesc(RxRegistrationAdvanceStudentInfo::getCreateTime);

        if (!isNullOrEmpty(stuName)) {
            studentInfoLambdaQueryWrapper.like(RxRegistrationAdvanceStudentInfo::getName, stuName);
        }

        if (!isNullOrEmpty(planId)) {
            studentInfoLambdaQueryWrapper.eq(RxRegistrationAdvanceStudentInfo::getPlanId, planId);
        }

        if (!isNullOrEmpty(idCard)) {
            studentInfoLambdaQueryWrapper.like(RxRegistrationAdvanceStudentInfo::getIdCard, idCard);
        }

        if (!isNullOrEmpty(majorId)) {
            studentInfoLambdaQueryWrapper.eq(RxRegistrationAdvanceStudentInfo::getOrgId, majorId);
        }

        if (!isNullOrEmpty(middleSchoolId)) {
            studentInfoLambdaQueryWrapper.eq(RxRegistrationAdvanceStudentInfo::getMiddleSchoolId, middleSchoolId);
        }
        if (!isNullOrEmpty(tel)) {
            studentInfoLambdaQueryWrapper.like(RxRegistrationAdvanceStudentInfo::getTel, tel);
        }
        if (!isNullOrEmpty(isStay)) {
            studentInfoLambdaQueryWrapper.eq(RxRegistrationAdvanceStudentInfo::getIsStay, isStay);
        }

        if (!isNullOrEmpty(isFilingStu)) {
            studentInfoLambdaQueryWrapper.eq(RxRegistrationAdvanceStudentInfo::getIsFilingStu, isFilingStu);
        }
        rxRegistrationAdvanceStudentInfoMapper.selectPage(page, studentInfoLambdaQueryWrapper);
        List<RxRegistrationAdvanceStudentInfoResp> list = page.getRecords()
                .stream()
                .map(rxRegistrationAdvanceStudentInfo -> {
                    RxRegistrationAdvanceStudentInfoResp resp = new RxRegistrationAdvanceStudentInfoResp();
                    BeanUtils.copyProperties(rxRegistrationAdvanceStudentInfo, resp);
                    resp.setStuId(rxRegistrationAdvanceStudentInfo.getId());
                    return resp;
                })
                .collect(Collectors.toList());
        return CommonResult.success(list, (int)page.getTotal());

    }

    @Override
    @Async
    public Future<ResponseResult> exportStuInfoList(RxRegistrationAdvanceStudentInfoBatchReq exportReq, HttpServletResponse response) {
       try {
           LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo> studentInfoLambdaQueryWrapper = new LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo>()
                   .orderByDesc(RxRegistrationAdvanceStudentInfo::getCreateTime);

           if (!isNullOrEmpty(exportReq.getStuName())) {
               studentInfoLambdaQueryWrapper.like(RxRegistrationAdvanceStudentInfo::getName, exportReq.getStuName());
           }

           if (!isNullOrEmpty(exportReq.getPlanId())) {
               studentInfoLambdaQueryWrapper.eq(RxRegistrationAdvanceStudentInfo::getPlanId, exportReq.getPlanId());
           }

           if (!isNullOrEmpty(exportReq.getIdCard())) {
               studentInfoLambdaQueryWrapper.like(RxRegistrationAdvanceStudentInfo::getIdCard,exportReq.getIdCard());
           }

           if (!isNullOrEmpty(exportReq.getMajorId())) {
               studentInfoLambdaQueryWrapper.eq(RxRegistrationAdvanceStudentInfo::getOrgId, exportReq.getMajorId());
           }

           if (!isNullOrEmpty(exportReq.getMiddleSchoolId())) {
               studentInfoLambdaQueryWrapper.eq(RxRegistrationAdvanceStudentInfo::getMiddleSchoolId, exportReq.getMiddleSchoolId());
           }
           if (!isNullOrEmpty(exportReq.getTel())) {
               studentInfoLambdaQueryWrapper.like(RxRegistrationAdvanceStudentInfo::getTel, exportReq.getTel());
           }
           if (!isNullOrEmpty(exportReq.getIsStay())) {
               studentInfoLambdaQueryWrapper.eq(RxRegistrationAdvanceStudentInfo::getIsStay, exportReq.getIsStay());
           }

           if (!isNullOrEmpty(exportReq.getIsFilingStu())) {
               studentInfoLambdaQueryWrapper.eq(RxRegistrationAdvanceStudentInfo::getIsFilingStu, exportReq.getIsFilingStu());
           }

           List<RxRegistrationAdvanceStudentInfoResp> list = rxRegistrationAdvanceStudentInfoMapper.selectList(studentInfoLambdaQueryWrapper)
                   .stream()
                   .map(rxRegistrationAdvanceStudentInfo -> {
                       RxRegistrationAdvanceStudentInfoResp resp = new RxRegistrationAdvanceStudentInfoResp();
                       BeanUtils.copyProperties(rxRegistrationAdvanceStudentInfo, resp);
                       return resp;
                   })
                   .collect(Collectors.toList());
           //表头数据
           String[] header = exportReq.getLimitColumn().toArray(new String[0]);
           double sheetNum;
           //声明一个工作簿
           HSSFWorkbook workbook = new HSSFWorkbook();
           if (list.size() > 0) {
               sheetNum = Math.ceil((double) list.size() / PER_SHEET_NUM);
               for (int k = 0; k < sheetNum; k++) {
                   //生成一个表格，设置表格名称为"资源导出表"
                   HSSFSheet sheet = workbook.createSheet("学生信息导出表" + (k + 1));

                   //设置表格列宽度为10个字节
                   sheet.setDefaultColumnWidth(12);
                   //创建标题的显示样式
                   HSSFCellStyle headerStyle = workbook.createCellStyle();
                   headerStyle.setFillForegroundColor(IndexedColors.YELLOW.index);
                   headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

                   HSSFFont f = workbook.createFont();
                   f.setFontHeightInPoints((short) 10);//字号
                   f.setBold(true);//加粗
                   headerStyle.setFont(f);
                   //创建第一行表头
                   HSSFRow headrow = sheet.createRow(0);

                   //遍历添加表头(下面模拟遍历学生，也是同样的操作过程)
                   for (int i = 0; i < header.length + 1; i++) {
                       //创建一个单元格
                       HSSFCell cell = headrow.createCell(i);

                       if (i == 0) {
                           //创建一个内容对象
                           HSSFRichTextString text = new HSSFRichTextString("序号");
                           //将内容对象的文字内容写入到单元格中
                           cell.setCellValue(text);
                           cell.setCellStyle(headerStyle);
                           continue;
                       }
                       //创建一个内容对象
                       String header1 = apiModelUtil.getFieldValueByFieldName(RxRegistrationAdvanceStudentInfoResp.class, header[i - 1]);
                       HSSFRichTextString text = new HSSFRichTextString(header1);

                       //将内容对象的文字内容写入到单元格中
                       cell.setCellValue(text);
                       cell.setCellStyle(headerStyle);

                   }



                   int range = PER_SHEET_NUM;
                   if (k + 1 == sheetNum) {
                       range = list.size() - (PER_SHEET_NUM) * k;
                   }
                   for (int i = 0; i < range; i++) {

                       //创建一行
                       HSSFRow row1 = sheet.createRow(i + 2);
                       RxRegistrationAdvanceStudentInfoResp studentInfoResp = list.get((PER_SHEET_NUM) * k + i);
                       Map map = JSONObject.parseObject(JSON.toJSONString(studentInfoResp), Map.class);
                       row1.createCell(0).setCellValue(new HSSFRichTextString(i + 1 + ""));
                       for (int j = 0; j < header.length; j++) {
                           String rowContent = "";
                           if(!isNullOrEmpty(map.get(header[j]))) {
                               if (map.get(header[j]) instanceof Long) {
                                   rowContent = TimeUtil.DateAllHanZi((long) map.get(header[j]));
                               }else if ((header[j].equals("advanceStatus") || header[j].equals("confirmStatus"))) {
                                   Integer advanceStatus = studentInfoResp.getAdvanceStatus();
                                   Integer confirmStatus = studentInfoResp.getConfirmStatus();
                                   if (advanceStatus == REGISTRATION_STATUS_FINISH || confirmStatus == REGISTRATION_STATUS_FINISH) {
                                       rowContent = "完成";
                                   } else {
                                       rowContent = "未完成";
                                   }

                               }else if(header[j].equals("isFilingStu")){
                                   Integer isFilingStu = studentInfoResp.getIsFilingStu();
                                   if (isFilingStu == 0 ) {
                                       rowContent = "普通学生";
                                   } else {
                                       rowContent = "建档学生";
                                   }
                               }else if(header[j].equals("isStay")){
                                   Integer isStay = studentInfoResp.getIsStay();
                                   if (isStay == IS_STAY ) {
                                       rowContent = "住校";
                                   } else{
                                       rowContent = "未住校";
                                   }

                               } else{
                                   rowContent = String.valueOf(map.get(header[j]));
                               }
                           }
                           row1.createCell(j + 1).setCellValue(new HSSFRichTextString(rowContent));
                       }
                   }
               }
           }


           response.setContentType("application/vnd.ms-excel;charset=utf-8");
           response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("学生信息导出表.xlsx", "utf-8"));
           response.setCharacterEncoding("utf-8");
           response.setHeader("file-type", "download");
           response.setHeader("file-name", URLEncoder.encode("学生信息导出表.xlsx", "utf-8"));
           response.setHeader("Access-Control-Expose-Headers", "file-type,file-name");
           //刷新缓冲
           response.flushBuffer();
           //workbook将Excel写入到response的输出流中，供页面下载
           OutputStream os = response.getOutputStream();
           workbook.write(os);

           workbook.close();
           os.close();
       } catch (Exception e) {
           e.printStackTrace();
           return new AsyncResult<>(CommonResult.failed(CommonCodeEnum.FAIL));
       }
        return null;
    }

    @Override
    @Async
    public Future<ResponseResult> batchAddOldStudentPaymentData(Map<String, Object> map, String user_id) {
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(map));
        //查询开启的计划
        RxRegistrationPlanSetting enablePlanInfo = planUtil.getEnablePlanInfo();
        if (enablePlanInfo == null) {
            return new AsyncResult<>(CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_PLAN_NOT_EXIST));
        }
        List<RxOldRegistrationAdvanceStudentInfoReq> oldRegistrationAdvanceStudentList = JSONObject.parseArray(JSON.toJSONString(jsonObject.get("list")), RxOldRegistrationAdvanceStudentInfoReq.class);
        if (oldRegistrationAdvanceStudentList == null || oldRegistrationAdvanceStudentList.size() < 1) {
            return new AsyncResult<>(CommonResult.failed(CommonCodeEnum.INVALID_PARAM));
        }
        //设置录取通知书序列号 D240001 这里只需要设置0001即可
        //获取当前年份后两位
        Date date = new Date(); // 假设这是2024年的某个日期
        SimpleDateFormat sdf = new SimpleDateFormat("yy");
        String yearLastTwo = sdf.format(date);
        int admissionNumber = 1;
        //通过录取通知书序列号排名
        List<RxRegistrationAdvanceStudentInfo> studentInfoList = rxRegistrationAdvanceStudentInfoMapper.selectList(new LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo>()
                .isNotNull(RxRegistrationAdvanceStudentInfo::getAdmissionNumber)
                .orderByDesc(RxRegistrationAdvanceStudentInfo::getAdmissionNumber));
        if (studentInfoList != null && studentInfoList.size() > 0) {
            admissionNumber = studentInfoList.get(0).getAdmissionNumber();
            String existYearLastTwo = String.valueOf(admissionNumber).substring(0, 2);
            if (!existYearLastTwo.equals(yearLastTwo)) {
                // 当年份变化时，直接使用新年的序列号
                String admissionNumberStr = yearLastTwo + "000" + admissionNumber;
                admissionNumber = Integer.parseInt(admissionNumberStr);
            }
            else {
                 //当年份相同时，仅递增序列号
                admissionNumber += 1;
            }
        } else {//第一个人缴费时 生成240001
            String admissionNumberStr = yearLastTwo + "000" + admissionNumber;
            admissionNumber = Integer.parseInt(admissionNumberStr);
        }
        //创建导入任务
        SmsImportTask smsImportTask = new SmsImportTask();
        smsImportTask.setTaskName(TASK_NAME_OLD_REGISTRATION__STUDENT_IMPORT);
        smsImportTask.setUserId(user_id);
        smsImportTask.setTaskType(TASK_TYPE_OLD_REGISTRATION_STUDENT_IMPORT);
        smsImportTaskMapper.insert(smsImportTask);
        batchAddOldStudentPaymentDataInfo(oldRegistrationAdvanceStudentList, smsImportTask.getId(),enablePlanInfo,admissionNumber,user_id);
        return new AsyncResult<>(CommonResult.success());
    }



    private void batchAddOldStudentPaymentDataInfo(List<RxOldRegistrationAdvanceStudentInfoReq> oldRegistrationAdvanceStudentList, String id,
                                                   RxRegistrationPlanSetting enablePlanInfo,Integer admissionNumber,String user_id) {
        int OFFSET_ROW = 2;
        int task_status = TASK_STATUS_DONE;


        for (int i = 0; i < oldRegistrationAdvanceStudentList.size(); i++) {
            //开启事务
            DefaultTransactionDefinition dt = new DefaultTransactionDefinition();
            // 嵌套事务 PROPAGATION_REQUIRES_NEW 每次开启一个新的事务
            dt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
            // 设置嵌套事务
            TransactionStatus status = transactionManager.getTransaction(dt);
            try {
                RxOldRegistrationAdvanceStudentInfoReq req = oldRegistrationAdvanceStudentList.get(i);
                if (isNullOrEmpty(req.getName(),req.getMiddleSchool(),req.getParentTel(),req.getSex(),req.getNation(),req.getIsStay(),
                        req.getIdCard(),req.getTel())) {
                    transactionManager.rollback(status);
                    task_status = TASK_STATUS_ERR;
                    createTeacherImportTaskDetail(id, REASON_INVALID_PARAM, (i + OFFSET_ROW) + "");
                    continue;
                }
                //校验身份证和电话
                boolean validIDCard = ParamCheckUtil.isValidIDCard(req.getIdCard());
                if (!validIDCard) {
                    transactionManager.rollback(status);
                    task_status = TASK_STATUS_ERR;
                    createTeacherImportTaskDetail(id, REASON_NEW_STUDENT_ID_CARD_FORMAT_ERROR, (i + OFFSET_ROW) + "");
                    continue;
                }
                boolean validPhone = ParamCheckUtil.isValidPhone(req.getTel());
                if (!validPhone) {
                    transactionManager.rollback(status);
                    task_status = TASK_STATUS_ERR;
                    createTeacherImportTaskDetail(id, REASON_NEW_STUDENT_PHONE_FORMAT_ERROR, (i + OFFSET_ROW) + "");
                    continue;
                }
                List<RxRegistrationAdvanceStudentInfo> studentInfoList = rxRegistrationAdvanceStudentInfoMapper.selectList(new LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo>()
                        .eq(RxRegistrationAdvanceStudentInfo::getPlanId, enablePlanInfo.getId())
                        .eq(RxRegistrationAdvanceStudentInfo::getIdCard, req.getIdCard()));
//                if (studentInfoList == null || studentInfoList.size() < 1) {
//                    transactionManager.rollback(status);
//                    task_status = TASK_STATUS_ERR;
//                    createTeacherImportTaskDetail(id, req.getIdCard() +REASON_REGISTRATION_STUDENT_INFO_NOT_EXIST, (i + OFFSET_ROW) + "");
//                    continue;
//                }
                if (studentInfoList != null && studentInfoList.size() > 0) {
                    Integer oldDataFlag = studentInfoList.get(0).getOldDataFlag();
                    transactionManager.rollback(status);
                    task_status = TASK_STATUS_ERR;
                    createTeacherImportTaskDetail(id, req.getIdCard() +"oldFlag:"+oldDataFlag+REASON_REGISTRATION_ID_CARD_EXIST, (i + OFFSET_ROW) + "");
                    continue;
                }


                //专业
                RxAdvanceRegistrationOrg advanceRegistrationOrg = new RxAdvanceRegistrationOrg();
                List<RxAdvanceRegistrationOrg> advanceRegistrationOrgList = rxAdvanceRegistrationOrgMapper.selectList(new LambdaQueryWrapper<RxAdvanceRegistrationOrg>()
                        .eq(RxAdvanceRegistrationOrg::getMajorName, req.getOrgName()));
                if (advanceRegistrationOrgList != null && advanceRegistrationOrgList.size() > 0) {
                    advanceRegistrationOrg = advanceRegistrationOrgList.get(0);
                }else {
                    transactionManager.rollback(status);
                    task_status = TASK_STATUS_ERR;
                    createTeacherImportTaskDetail(id, req.getIdCard()+"的"+REASON_ADVANCE_REGISTRATION_ORG_NOT_EXIST, (i + OFFSET_ROW) + "");
                    continue;
                }
                //毕业学校
                RxAdvanceRegistrationMiddleSchool rxAdvanceRegistrationMiddleSchool = new RxAdvanceRegistrationMiddleSchool();
                List<RxAdvanceRegistrationMiddleSchool> middleSchoolList = rxAdvanceRegistrationMiddleSchoolMapper.selectList(new LambdaQueryWrapper<RxAdvanceRegistrationMiddleSchool>()
                        .eq(RxAdvanceRegistrationMiddleSchool::getMiddleSchoolName, req.getMiddleSchool()));
                if (middleSchoolList != null && middleSchoolList.size() > 0) {
                   rxAdvanceRegistrationMiddleSchool = middleSchoolList.get(0);
                }else {
                    transactionManager.rollback(status);
                    task_status = TASK_STATUS_ERR;
                    createTeacherImportTaskDetail(id, req.getIdCard()+"的"+REASON_ADVANCE_REGISTRATION_MIDDLE_SCHOOL_NOT_EXIST, (i + OFFSET_ROW) + "");
                    continue;
                }
                if (req.getPaymentAmount().equals("0")) {
                    RxRegistrationAdvanceStudentInfo rxRegistrationAdvanceStudentInfo = new RxRegistrationAdvanceStudentInfo();
                    BeanUtils.copyProperties(req, rxRegistrationAdvanceStudentInfo);
                    rxRegistrationAdvanceStudentInfo.setMiddleSchoolId(rxAdvanceRegistrationMiddleSchool.getId());
                    rxRegistrationAdvanceStudentInfo.setMiddleSchool(rxAdvanceRegistrationMiddleSchool.getMiddleSchoolName());
                    rxRegistrationAdvanceStudentInfo.setPlanId(enablePlanInfo.getId());
                    rxRegistrationAdvanceStudentInfo.setPlanName(enablePlanInfo.getPlanName());
                    rxRegistrationAdvanceStudentInfo.setOrgId(advanceRegistrationOrg.getId());
                    rxRegistrationAdvanceStudentInfo.setOrgName(advanceRegistrationOrg.getMajorName());
                    rxRegistrationAdvanceStudentInfo.setAdvanceStatus(REGISTRATION_STATUS_GOING_ON);
                    rxRegistrationAdvanceStudentInfo.setOldDataFlag(1);
                    rxRegistrationAdvanceStudentInfoMapper.insert(rxRegistrationAdvanceStudentInfo);
                }else {
                    //新增学生信息
                    RxRegistrationAdvanceStudentInfo rxRegistrationAdvanceStudentInfo = new RxRegistrationAdvanceStudentInfo();
                    BeanUtils.copyProperties(req, rxRegistrationAdvanceStudentInfo);
                    rxRegistrationAdvanceStudentInfo.setMiddleSchoolId(rxAdvanceRegistrationMiddleSchool.getId());
                    rxRegistrationAdvanceStudentInfo.setMiddleSchool(rxAdvanceRegistrationMiddleSchool.getMiddleSchoolName());
                    rxRegistrationAdvanceStudentInfo.setPlanId(enablePlanInfo.getId());
                    rxRegistrationAdvanceStudentInfo.setPlanName(enablePlanInfo.getPlanName());
                    rxRegistrationAdvanceStudentInfo.setOrgId(advanceRegistrationOrg.getId());
                    rxRegistrationAdvanceStudentInfo.setOrgName(advanceRegistrationOrg.getMajorName());
                    rxRegistrationAdvanceStudentInfo.setAdmissionNumber(admissionNumber);
                    rxRegistrationAdvanceStudentInfo.setAdvanceStatus(REGISTRATION_STATUS_FINISH);
                    rxRegistrationAdvanceStudentInfo.setOldDataFlag(1);
                    rxRegistrationAdvanceStudentInfoMapper.insert(rxRegistrationAdvanceStudentInfo);
                    String studentInfoId = rxRegistrationAdvanceStudentInfo.getId();
                    if (isNullOrEmpty(studentInfoId)) {
                        transactionManager.rollback(status);
                        task_status = TASK_STATUS_ERR;
                        createTeacherImportTaskDetail(id, REASON_FAIL, (i + OFFSET_ROW) + "");
                        continue;
                    }
                    //添加缴费信息
                    RxRegistrationChargePaymentRecord paymentRecord = new RxRegistrationChargePaymentRecord(); // 新生成的支付记录
                    paymentRecord.setType(RX_REGISTRATION_CHARGE_PAYMENT_RECORD_TYPE_ADVANCE);
                    paymentRecord.setPaymentTime(TimeUtil.StringtoDate(req.getPaymentTime()));
                    paymentRecord.setMode(0);
                    paymentRecord.setStuId(studentInfoId);
                    paymentRecord.setConfigName("自贡市职业培训学院学费");
                    paymentRecord.setPlanId(enablePlanInfo.getId());
                    paymentRecord.setPaymentAmount(new BigDecimal(req.getPaymentAmount()));
                    rxRegistrationChargePaymentRecordMapper.insert(paymentRecord);
                    String paymentRecordId = paymentRecord.getId();
                    if (isNullOrEmpty(studentInfoId)) {
                        transactionManager.rollback(status);
                        task_status = TASK_STATUS_ERR;
                        createTeacherImportTaskDetail(id, REASON_FAIL, (i + OFFSET_ROW) + "");
                        continue;
                    }
                    String categoryId = "1797802343541399553";
                    String categoryName = "预报名费用";
                    String categoryDetailId = "";
                    String categoryDetailName = "";
                    BigDecimal categoryAmount = new BigDecimal(req.getPaymentAmount());
                    if (req.getPaymentAmount().equals("200")) {
                        categoryDetailId = "1801451784655785986";
                        categoryDetailName = "脱贫户学生";
                    }else if (req.getPaymentAmount().equals("300")) {
                        categoryDetailId = "1797802414739709953";
                        categoryDetailName = "普通学生";
                    }
                    //缴费详情
                    RxRegistrationChargePaymentCategoryDivide categoryDivide = new RxRegistrationChargePaymentCategoryDivide();
                    categoryDivide.setStuId(studentInfoId);
                    categoryDivide.setPlanId(enablePlanInfo.getId());
                    categoryDivide.setPaymentRecordId(paymentRecordId);
                    categoryDivide.setCategoryId(categoryId);//正式
                    categoryDivide.setCategoryDetailId(categoryDetailId);//正式
                    categoryDivide.setCategoryDetailName(categoryDetailName);
                    categoryDivide.setCategoryName(categoryName);
                    categoryDivide.setAmount(categoryAmount);
                    categoryDivide.setPaymentTime(TimeUtil.StringtoDate(req.getPaymentTime()));
                    rxRegistrationChargePaymentCategoryDivideMapper.insert(categoryDivide);
                    //已缴费项记录
                    RxRegistrationChargeCategoryRecord record = new RxRegistrationChargeCategoryRecord();
                    record.setStuId(studentInfoId);
                    record.setAppType(APP_TYPE_ADVANCE);
                    record.setMainId(categoryId);
                    record.setMainName(categoryName);
                    record.setPrice(categoryAmount);
                    record.setChildId(categoryDetailId);
                    record.setChildName(categoryDetailName);
                    rxRegistrationChargeCategoryRecordMapper.insert(record);
                }

                transactionManager.commit(status);
            } catch (Exception e) {
                transactionManager.rollback(status);
                task_status = TASK_STATUS_ERR;
                createTeacherImportTaskDetail(id, REASON_IMPORT_ERR, (i + OFFSET_ROW) + "");
            }finally {
                if (status.isNewTransaction() && !status.isCompleted()) {
                    transactionManager.commit(status);
                }
            }
            admissionNumber +=1;
        }
        SmsImportTask smsImportTask = new SmsImportTask();
        smsImportTask.setId(id);
        smsImportTask.setStatus(task_status);
        smsImportTaskMapper.updateById(smsImportTask);
    }

    private void createTeacherImportTaskDetail(String id, String reason, String row) {
        SmsImportTaskDetail smsImportTaskDetail = new SmsImportTaskDetail();
        smsImportTaskDetail.setTaskId(id);
        smsImportTaskDetail.setFailReason(reason);
        smsImportTaskDetail.setFailRow(row);
        smsImportTaskDetailMapper.insert(smsImportTaskDetail);
    }

    @Override
    public ResponseResult addCategoryRecord() {
        List<RxRegistrationAdvanceStudentInfo> studentInfoList = rxRegistrationAdvanceStudentInfoMapper.selectList(new LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo>()
                .eq(RxRegistrationAdvanceStudentInfo::getAdvanceStatus, REGISTRATION_STATUS_FINISH)
        .eq(RxRegistrationAdvanceStudentInfo::getOldDataFlag,1));
        if (studentInfoList == null || studentInfoList.size() < 1) {
           return CommonResult.success();
        }
        for (RxRegistrationAdvanceStudentInfo studentInfo : studentInfoList) {
            List<RxRegistrationChargeCategoryRecord> categoryRecordList = rxRegistrationChargeCategoryRecordMapper.selectList(new LambdaQueryWrapper<RxRegistrationChargeCategoryRecord>()
                    .eq(RxRegistrationChargeCategoryRecord::getAppType, 1)
                    .eq(RxRegistrationChargeCategoryRecord::getMainId,"1797802343541399553")
                    .eq(RxRegistrationChargeCategoryRecord::getStuId, studentInfo.getId()));
            if (categoryRecordList == null || categoryRecordList.size() < 1) {
                RxRegistrationChargeCategoryRecord record = new RxRegistrationChargeCategoryRecord();
                record.setStuId(studentInfo.getId());
                record.setAppType(APP_TYPE_ADVANCE);
                record.setMainId("1797802343541399553");
                record.setMainName("预报名费用");
                record.setPrice(new BigDecimal(300));
                record.setChildId("1797802414739709953");
                record.setChildName("普通学生");
                rxRegistrationChargeCategoryRecordMapper.insert(record);
            }
        }

        return CommonResult.success();
    }

    @Override
    @Transactional
    public ResponseResult deletedOldData() {
        //查导入学生老数据
        LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo> studentInfoLambdaQueryWrapper = new LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo>()
                .eq(RxRegistrationAdvanceStudentInfo::getOldDataFlag, 1);
        List<String> stuIdList = rxRegistrationAdvanceStudentInfoMapper.selectList(studentInfoLambdaQueryWrapper)
                .stream().map(RxRegistrationAdvanceStudentInfo::getId).collect(Collectors.toList());
        if (stuIdList.size() < 1) {
            return CommonResult.success();
        }
        RxRegistrationPlanSetting enablePlanInfo = planUtil.getEnablePlanInfo();
        if (enablePlanInfo == null) {
            return CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_PLAN_NOT_EXIST);
        }
        //删除缴费记录

        //查询缴费记录
        List<String> paymentIdList = rxRegistrationChargePaymentRecordMapper.selectList(new LambdaQueryWrapper<RxRegistrationChargePaymentRecord>()
                .eq(RxRegistrationChargePaymentRecord::getPlanId, enablePlanInfo.getId())
                .in(RxRegistrationChargePaymentRecord::getStuId, stuIdList))
                .stream()
                .map(RxRegistrationChargePaymentRecord::getId).collect(Collectors.toList());
        //删除缴费详情记录
        rxRegistrationChargePaymentCategoryDivideMapper.delete(new LambdaQueryWrapper<RxRegistrationChargePaymentCategoryDivide>()
                .in(RxRegistrationChargePaymentCategoryDivide::getPaymentRecordId, paymentIdList));
        //删除缴费记录
        rxRegistrationChargePaymentRecordMapper.delete(new LambdaQueryWrapper<RxRegistrationChargePaymentRecord>()
        .in(RxRegistrationChargePaymentRecord::getStuId,stuIdList)
        .eq(RxRegistrationChargePaymentRecord::getPlanId,enablePlanInfo.getId()));
        //删除已缴费项记录
        rxRegistrationChargeCategoryRecordMapper.delete(new LambdaQueryWrapper<RxRegistrationChargeCategoryRecord>()
        .in(RxRegistrationChargeCategoryRecord::getStuId,stuIdList)
        .eq(RxRegistrationChargeCategoryRecord::getAppType, APP_TYPE_ADVANCE));
        //删除学生信息
        rxRegistrationAdvanceStudentInfoMapper.delete(studentInfoLambdaQueryWrapper);
        return CommonResult.success();
    }

    @Override
    @Async
    public Future<ResponseResult> batchAddOldPaymentData(Map<String, Object> map, String user_id) {
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(map));
        //查询开启的计划
        RxRegistrationPlanSetting enablePlanInfo = planUtil.getEnablePlanInfo();
        if (enablePlanInfo == null) {
            return new AsyncResult<>(CommonResult.failed(CommonCodeEnum.RX_REGISTRATION_ADVANCE_PLAN_NOT_EXIST));
        }
        List<RxOldRegistrationAdvanceStudentInfoReq> oldRegistrationAdvanceStudentList = JSONObject.parseArray(JSON.toJSONString(jsonObject.get("list")), RxOldRegistrationAdvanceStudentInfoReq.class);
        if (oldRegistrationAdvanceStudentList == null || oldRegistrationAdvanceStudentList.size() < 1) {
            return new AsyncResult<>(CommonResult.failed(CommonCodeEnum.INVALID_PARAM));
        }
        //设置录取通知书序列号 D240001 这里只需要设置0001即可
        //获取当前年份后两位
        Date date = new Date(); // 假设这是2024年的某个日期
        SimpleDateFormat sdf = new SimpleDateFormat("yy");
        String yearLastTwo = sdf.format(date);
        int admissionNumber = 1;
        //通过录取通知书序列号排名
        List<RxRegistrationAdvanceStudentInfo> studentInfoList = rxRegistrationAdvanceStudentInfoMapper.selectList(new LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo>()
                .isNotNull(RxRegistrationAdvanceStudentInfo::getAdmissionNumber)
                .orderByDesc(RxRegistrationAdvanceStudentInfo::getAdmissionNumber));
        if (studentInfoList != null && studentInfoList.size() > 0) {
            admissionNumber = studentInfoList.get(0).getAdmissionNumber();
            String existYearLastTwo = String.valueOf(admissionNumber).substring(0, 2);
            if (!existYearLastTwo.equals(yearLastTwo)) {
                // 当年份变化时，直接使用新年的序列号
                String admissionNumberStr = yearLastTwo + "000" + admissionNumber;
                admissionNumber = Integer.parseInt(admissionNumberStr);
            }
            else {
                //当年份相同时，仅递增序列号
                admissionNumber += 1;
            }
        } else {//第一个人缴费时 生成240001
            String admissionNumberStr = yearLastTwo + "000" + admissionNumber;
            admissionNumber = Integer.parseInt(admissionNumberStr);
        }
        //创建导入任务
        SmsImportTask smsImportTask = new SmsImportTask();
        smsImportTask.setTaskName(TASK_NAME_OLD_REGISTRATION__STUDENT_IMPORT);
        smsImportTask.setUserId(user_id);
        smsImportTask.setTaskType(TASK_TYPE_TWO_OLD_REGISTRATION_STUDENT_IMPORT);
        smsImportTaskMapper.insert(smsImportTask);
        batchAddTwoOldStudentPaymentDataInfo(oldRegistrationAdvanceStudentList, smsImportTask.getId(),enablePlanInfo,admissionNumber,user_id);
        return new AsyncResult<>(CommonResult.success());
    }



    private void batchAddTwoOldStudentPaymentDataInfo(List<RxOldRegistrationAdvanceStudentInfoReq> oldRegistrationAdvanceStudentList, String id,
                                                   RxRegistrationPlanSetting enablePlanInfo,Integer admissionNumber,String user_id) {
        int OFFSET_ROW = 2;
        int task_status = TASK_STATUS_DONE;


        for (int i = 0; i < oldRegistrationAdvanceStudentList.size(); i++) {
            //开启事务
            DefaultTransactionDefinition dt = new DefaultTransactionDefinition();
            // 嵌套事务 PROPAGATION_REQUIRES_NEW 每次开启一个新的事务
            dt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
            // 设置嵌套事务
            TransactionStatus status = transactionManager.getTransaction(dt);
            try {
                RxOldRegistrationAdvanceStudentInfoReq req = oldRegistrationAdvanceStudentList.get(i);
                if (isNullOrEmpty(req.getName(),req.getMiddleSchool(),req.getSex(),req.getNation(),
                        req.getIdCard())) {
                    transactionManager.rollback(status);
                    task_status = TASK_STATUS_ERR;
                    createTeacherImportTaskDetail(id, REASON_INVALID_PARAM, (i + OFFSET_ROW) + "");
                    continue;
                }
                //校验身份证
                boolean validIDCard = ParamCheckUtil.isValidIDCard(req.getIdCard());
                if (!validIDCard) {
                    transactionManager.rollback(status);
                    task_status = TASK_STATUS_ERR;
                    createTeacherImportTaskDetail(id, REASON_NEW_STUDENT_ID_CARD_FORMAT_ERROR, (i + OFFSET_ROW) + "");
                    continue;
                }

                List<RxRegistrationAdvanceStudentInfo> studentInfoList = rxRegistrationAdvanceStudentInfoMapper.selectList(new LambdaQueryWrapper<RxRegistrationAdvanceStudentInfo>()
                        .eq(RxRegistrationAdvanceStudentInfo::getPlanId, enablePlanInfo.getId())
                        .eq(RxRegistrationAdvanceStudentInfo::getIdCard, req.getIdCard()));
                if (studentInfoList == null || studentInfoList.size() < 1) {
                    transactionManager.rollback(status);
                    task_status = TASK_STATUS_ERR;
                    createTeacherImportTaskDetail(id, req.getIdCard() + "的" + REASON_REGISTRATION_STUDENT_INFO_NOT_EXIST, (i + OFFSET_ROW) + "");
                    continue;
                }
                RxRegistrationAdvanceStudentInfo studentInfo = studentInfoList.get(0);
                String studentInfoId = studentInfoList.get(0).getId();
                if (!req.getPaymentAmount().equals("0")) {
                    List<RxRegistrationChargePaymentRecord> paymentRecordList = rxRegistrationChargePaymentRecordMapper.selectList(new LambdaQueryWrapper<RxRegistrationChargePaymentRecord>()
                            .eq(RxRegistrationChargePaymentRecord::getType, RX_REGISTRATION_CHARGE_PAYMENT_RECORD_TYPE_ADVANCE)
                            .eq(RxRegistrationChargePaymentRecord::getPlanId, enablePlanInfo.getId())
                            .eq(RxRegistrationChargePaymentRecord::getStuId, studentInfoList.get(0).getId())
                            .eq(RxRegistrationChargePaymentRecord::getPaymentAmount, new BigDecimal("300")));
                    if (paymentRecordList == null || paymentRecordList.size() < 1) {
                        //修好学生状态2
                        Integer oldDataFlag = studentInfo.getOldDataFlag();
                        if (oldDataFlag == null) {
                            oldDataFlag = 0;
                        }
                        studentInfo.setAdvanceStatus(REGISTRATION_STATUS_FINISH);
                        studentInfo.setOldDataFlag(oldDataFlag + 1);
                        rxRegistrationAdvanceStudentInfoMapper.updateById(studentInfo);
                        //添加缴费信息
                        RxRegistrationChargePaymentRecord paymentRecord = new RxRegistrationChargePaymentRecord(); // 新生成的支付记录
                        paymentRecord.setType(RX_REGISTRATION_CHARGE_PAYMENT_RECORD_TYPE_ADVANCE);
                        paymentRecord.setPaymentTime(TimeUtil.StringtoDate(req.getPaymentTime()));
                        paymentRecord.setMode(0);
                        paymentRecord.setStuId(studentInfoId);
                        paymentRecord.setConfigName("自贡市职业培训学院学费");
                        paymentRecord.setPlanId(enablePlanInfo.getId());
                        paymentRecord.setPaymentAmount(new BigDecimal(req.getPaymentAmount()));
                        rxRegistrationChargePaymentRecordMapper.insert(paymentRecord);
                        String paymentRecordId = paymentRecord.getId();
                        if (isNullOrEmpty(studentInfoId)) {
                            transactionManager.rollback(status);
                            task_status = TASK_STATUS_ERR;
                            createTeacherImportTaskDetail(id, REASON_FAIL, (i + OFFSET_ROW) + "");
                            continue;
                        }
                        String categoryId = "1797802343541399553";
                        String categoryName = "预报名费用";
                        String categoryDetailId = "";
                        String categoryDetailName = "";
                        BigDecimal categoryAmount = new BigDecimal(req.getPaymentAmount());
                        if (req.getPaymentAmount().equals("200")) {
                            categoryDetailId = "1801451784655785986";
                            categoryDetailName = "脱贫户学生";
                        } else if (req.getPaymentAmount().equals("300")) {
                            categoryDetailId = "1797802414739709953";
                            categoryDetailName = "普通学生";
                        }
                        //缴费详情
                        RxRegistrationChargePaymentCategoryDivide categoryDivide = new RxRegistrationChargePaymentCategoryDivide();
                        categoryDivide.setStuId(studentInfoId);
                        categoryDivide.setPlanId(enablePlanInfo.getId());
                        categoryDivide.setPaymentRecordId(paymentRecordId);
                        categoryDivide.setCategoryId(categoryId);//正式
                        categoryDivide.setCategoryDetailId(categoryDetailId);//正式
                        categoryDivide.setCategoryDetailName(categoryDetailName);
                        categoryDivide.setCategoryName(categoryName);
                        categoryDivide.setAmount(categoryAmount);
                        categoryDivide.setPaymentTime(TimeUtil.StringtoDate(req.getPaymentTime()));
                        rxRegistrationChargePaymentCategoryDivideMapper.insert(categoryDivide);
                        //已缴费项记录
                        RxRegistrationChargeCategoryRecord record = new RxRegistrationChargeCategoryRecord();
                        record.setStuId(studentInfoId);
                        record.setAppType(APP_TYPE_ADVANCE);
                        record.setMainId(categoryId);
                        record.setMainName(categoryName);
                        record.setPrice(categoryAmount);
                        record.setChildId(categoryDetailId);
                        record.setChildName(categoryDetailName);
                        rxRegistrationChargeCategoryRecordMapper.insert(record);
                    }
                }



//                //专业
//                RxAdvanceRegistrationOrg advanceRegistrationOrg = new RxAdvanceRegistrationOrg();
//                List<RxAdvanceRegistrationOrg> advanceRegistrationOrgList = rxAdvanceRegistrationOrgMapper.selectList(new LambdaQueryWrapper<RxAdvanceRegistrationOrg>()
//                        .eq(RxAdvanceRegistrationOrg::getMajorName, req.getOrgName()));
//                if (advanceRegistrationOrgList != null && advanceRegistrationOrgList.size() > 0) {
//                    advanceRegistrationOrg = advanceRegistrationOrgList.get(0);
//                }else {
//                    transactionManager.rollback(status);
//                    task_status = TASK_STATUS_ERR;
//                    createTeacherImportTaskDetail(id, req.getIdCard()+"的"+REASON_ADVANCE_REGISTRATION_ORG_NOT_EXIST, (i + OFFSET_ROW) + "");
//                    continue;
//                }
//                //毕业学校
//                RxAdvanceRegistrationMiddleSchool rxAdvanceRegistrationMiddleSchool = new RxAdvanceRegistrationMiddleSchool();
//                List<RxAdvanceRegistrationMiddleSchool> middleSchoolList = rxAdvanceRegistrationMiddleSchoolMapper.selectList(new LambdaQueryWrapper<RxAdvanceRegistrationMiddleSchool>()
//                        .eq(RxAdvanceRegistrationMiddleSchool::getMiddleSchoolName, req.getMiddleSchool()));
//                if (middleSchoolList != null && middleSchoolList.size() > 0) {
//                    rxAdvanceRegistrationMiddleSchool = middleSchoolList.get(0);
//                }else {
//                    transactionManager.rollback(status);
//                    task_status = TASK_STATUS_ERR;
//                    createTeacherImportTaskDetail(id, req.getIdCard()+"的"+REASON_ADVANCE_REGISTRATION_MIDDLE_SCHOOL_NOT_EXIST, (i + OFFSET_ROW) + "");
//                    continue;
//                }
//                if (req.getPaymentAmount().equals("0")) {
//                    RxRegistrationAdvanceStudentInfo rxRegistrationAdvanceStudentInfo = new RxRegistrationAdvanceStudentInfo();
//                    BeanUtils.copyProperties(req, rxRegistrationAdvanceStudentInfo);
//                    rxRegistrationAdvanceStudentInfo.setMiddleSchoolId(rxAdvanceRegistrationMiddleSchool.getId());
//                    rxRegistrationAdvanceStudentInfo.setMiddleSchool(rxAdvanceRegistrationMiddleSchool.getMiddleSchoolName());
//                    rxRegistrationAdvanceStudentInfo.setPlanId(enablePlanInfo.getId());
//                    rxRegistrationAdvanceStudentInfo.setPlanName(enablePlanInfo.getPlanName());
//                    rxRegistrationAdvanceStudentInfo.setOrgId(advanceRegistrationOrg.getId());
//                    rxRegistrationAdvanceStudentInfo.setOrgName(advanceRegistrationOrg.getMajorName());
//                    rxRegistrationAdvanceStudentInfo.setAdvanceStatus(REGISTRATION_STATUS_GOING_ON);
//                    rxRegistrationAdvanceStudentInfo.setOldDataFlag(1);
//                    rxRegistrationAdvanceStudentInfoMapper.insert(rxRegistrationAdvanceStudentInfo);
//                }else {
//                    //新增学生信息
//                    RxRegistrationAdvanceStudentInfo rxRegistrationAdvanceStudentInfo = new RxRegistrationAdvanceStudentInfo();
//                    BeanUtils.copyProperties(req, rxRegistrationAdvanceStudentInfo);
//                    rxRegistrationAdvanceStudentInfo.setMiddleSchoolId(rxAdvanceRegistrationMiddleSchool.getId());
//                    rxRegistrationAdvanceStudentInfo.setMiddleSchool(rxAdvanceRegistrationMiddleSchool.getMiddleSchoolName());
//                    rxRegistrationAdvanceStudentInfo.setPlanId(enablePlanInfo.getId());
//                    rxRegistrationAdvanceStudentInfo.setPlanName(enablePlanInfo.getPlanName());
//                    rxRegistrationAdvanceStudentInfo.setOrgId(advanceRegistrationOrg.getId());
//                    rxRegistrationAdvanceStudentInfo.setOrgName(advanceRegistrationOrg.getMajorName());
//                    rxRegistrationAdvanceStudentInfo.setAdmissionNumber(admissionNumber);
//                    rxRegistrationAdvanceStudentInfo.setAdvanceStatus(REGISTRATION_STATUS_FINISH);
//                    rxRegistrationAdvanceStudentInfo.setOldDataFlag(1);
//                    rxRegistrationAdvanceStudentInfoMapper.insert(rxRegistrationAdvanceStudentInfo);
//                    String studentInfoId = rxRegistrationAdvanceStudentInfo.getId();
//                    if (isNullOrEmpty(studentInfoId)) {
//                        transactionManager.rollback(status);
//                        task_status = TASK_STATUS_ERR;
//                        createTeacherImportTaskDetail(id, REASON_FAIL, (i + OFFSET_ROW) + "");
//                        continue;
//                    }
//                    //添加缴费信息
//                    RxRegistrationChargePaymentRecord paymentRecord = new RxRegistrationChargePaymentRecord(); // 新生成的支付记录
//                    paymentRecord.setType(RX_REGISTRATION_CHARGE_PAYMENT_RECORD_TYPE_ADVANCE);
//                    paymentRecord.setPaymentTime(TimeUtil.StringtoDate(req.getPaymentTime()));
//                    paymentRecord.setMode(0);
//                    paymentRecord.setStuId(studentInfoId);
//                    paymentRecord.setConfigName("自贡市职业培训学院学费");
//                    paymentRecord.setPlanId(enablePlanInfo.getId());
//                    paymentRecord.setPaymentAmount(new BigDecimal(req.getPaymentAmount()));
//                    rxRegistrationChargePaymentRecordMapper.insert(paymentRecord);
//                    String paymentRecordId = paymentRecord.getId();
//                    if (isNullOrEmpty(studentInfoId)) {
//                        transactionManager.rollback(status);
//                        task_status = TASK_STATUS_ERR;
//                        createTeacherImportTaskDetail(id, REASON_FAIL, (i + OFFSET_ROW) + "");
//                        continue;
//                    }
//                    String categoryId = "1797802343541399553";
//                    String categoryName = "预报名费用";
//                    String categoryDetailId = "";
//                    String categoryDetailName = "";
//                    BigDecimal categoryAmount = new BigDecimal(req.getPaymentAmount());
//                    if (req.getPaymentAmount().equals("200")) {
//                        categoryDetailId = "1801451784655785986";
//                        categoryDetailName = "脱贫户学生";
//                    }else if (req.getPaymentAmount().equals("300")) {
//                        categoryDetailId = "1797802414739709953";
//                        categoryDetailName = "普通学生";
//                    }
//                    //缴费详情
//                    RxRegistrationChargePaymentCategoryDivide categoryDivide = new RxRegistrationChargePaymentCategoryDivide();
//                    categoryDivide.setStuId(studentInfoId);
//                    categoryDivide.setPlanId(enablePlanInfo.getId());
//                    categoryDivide.setPaymentRecordId(paymentRecordId);
//                    categoryDivide.setCategoryId(categoryId);//正式
//                    categoryDivide.setCategoryDetailId(categoryDetailId);//正式
//                    categoryDivide.setCategoryDetailName(categoryDetailName);
//                    categoryDivide.setCategoryName(categoryName);
//                    categoryDivide.setAmount(categoryAmount);
//                    categoryDivide.setPaymentTime(TimeUtil.StringtoDate(req.getPaymentTime()));
//                    rxRegistrationChargePaymentCategoryDivideMapper.insert(categoryDivide);
//                    //已缴费项记录
//                    RxRegistrationChargeCategoryRecord record = new RxRegistrationChargeCategoryRecord();
//                    record.setStuId(studentInfoId);
//                    record.setAppType(APP_TYPE_ADVANCE);
//                    record.setMainId(categoryId);
//                    record.setMainName(categoryName);
//                    record.setPrice(categoryAmount);
//                    record.setChildId(categoryDetailId);
//                    record.setChildName(categoryDetailName);
//                    rxRegistrationChargeCategoryRecordMapper.insert(record);
//                }

//                transactionManager.commit(status);
            } catch (Exception e) {
                transactionManager.rollback(status);
                task_status = TASK_STATUS_ERR;
                createTeacherImportTaskDetail(id, REASON_IMPORT_ERR, (i + OFFSET_ROW) + "");
            }finally {
                if (status.isNewTransaction() && !status.isCompleted()) {
                    transactionManager.commit(status);
                }
            }
            admissionNumber +=1;
        }
        SmsImportTask smsImportTask = new SmsImportTask();
        smsImportTask.setId(id);
        smsImportTask.setStatus(task_status);
        smsImportTaskMapper.updateById(smsImportTask);
    }
}
